﻿using System.Collections;
using UnityEditor.Animations;
using UnityEngine;
using System;
using Unity.Mathematics;

namespace GameBasic.Editors
{
    public static class AnimatorControllerExt
    {
        /// <summary>
        /// Loop through all state in the AnimatorController
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="action">int3(index, layer, indexInLayer)</param>
        public static void ForeachState(this AnimatorController controller, Action<int3, AnimatorState> action)
        {
            // layers
            var layers = controller.layers;
            int index = 0;
            // TODO: layer may contains same state
            for (int i = 0; i < 1; i++)
            {
                // states
                var states = layers[i].stateMachine.states;
                for (int j = 0; j < states.Length; j++)
                {
                    var state = states[j].state;
                    //AnimationClip clip = state.motion as AnimationClip;
                    action(new int3(index, i, j), state);
                    index++;
                }
            }
        }
    }
}